﻿/**********************************************************************************
 * Project Name :   
 * Remarks      :  
 * Class Name   :  AssertXml 
 * Version      :  v1.0.0.0 
 * Author       :  Joey Liang 
 * Description  : 
 * Created Time :  2013/10/16 21:53:50
 * Update Man   :  Joey Liang
 * Update Time  :  2013/10/16 21:53:50
************************************************************************/

using IdleTest.MSTest;
using System.Xml;

namespace IdleTest.Xml
{
    public class AssertXml : AssertInstance
    {
        public override void AreEqual<T>(T expected, T actual, bool areEqual = true, System.Func<T, T, bool> compareFunc = null, string message = null)
        {
            if (typeof(T) == typeof(XmlNode))
            {
                XmlNode expectedNode = expected as XmlNode;
                XmlNode actualNode = actual as XmlNode;

                if (!areEqual)
                {
                    if (expected == null && actual == null)
                    {
                        base.Fail("要断言不相等的两个对象均为为null，故断言相等失败！");
                    }
                }
                else if (expected == null && actual == null)
                {
                    return;
                }
                else if (expected == null || actual == null)
                {
                    base.Fail("由于要断言相等的两个实体之中只有一个为null，故断言相等失败！");
                }

                base.AreEqual(expectedNode.Name, actualNode.Name, areEqual);
                base.AreEqual(expectedNode.Value, actualNode.Value, areEqual);
                base.AreEqual(expectedNode.OuterXml, actualNode.OuterXml, areEqual);
                //base.AreEqual<XmlNode>(expectedNode, actualNode, areEqual);
            }
            else
            {
                base.AreEqual<T>(expected, actual, areEqual, compareFunc, message);
            }
        }

        public override void IsEmpty<T>(T actual, bool isEmpty = true, string message = null)
        {
            base.IsEmpty(actual, isEmpty, message);
            if (actual != null && actual is XmlNode)
            {
                base.IsEmpty((actual as XmlNode).OuterXml, isEmpty, message);
            }
        }
    }
}
